<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/6
 * Time: 15:19
 */

namespace Admin\Controller;


use Think\Controller;

class LoginController extends Controller
{
    public function index(){
        if(IS_POST){
            $data = I('post.');
            $verify = new \Think\Verify();
            $username = trim($data['username']);
            $password = trim($data['password']);
            if(empty($username) || empty($password)){
                $this->error('用户名/密码不能为空');
            }
            if($verify->check($data['code'], '')){
//            if(true){
                $res = M('Admin')->where(array('name'=>$username))->find();
                if(empty($res) || md5($password.$res['key']) != $res['password']){
                    $this->error('用户名/密码不正确');
                }
                session('u_data',$res);
                $this->success('登陆成功');
            }else{
                $this->error('验证码不正确');
            }
        }else{
            $this->assign('title','登陆');
            $this->display();
        }
    }
    public function logout(){
        session('u_data',null);
        $this->redirect('Login/index');
    }
    public function verity(){
        $config =    array(
            'fontSize'    =>    40,    // 验证码字体大小
            'length'      =>    4,     // 验证码位数
            'useNoise'    =>    false, // 关闭验证码杂点
        );
        $Verify =   new \Think\Verify($config);
        $Verify->entry();
    }
}